<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="./css/mui.min.css">

		<style>
			html,
			body {
				background-color: #f9f1f2;
			}
			
			.mui-bar {
				background-color: white;
				border-bottom: 1px solid rgba(0, 0, 0, .1);
			}
			
			header>.mui-row>.mui-col-sm-11>.mui-input-row {
				width: 90%;
				position: relative;
				left: 5%;
			}
			
			header>.mui-row>.mui-col-sm-11>.mui-input-row {
				height: 40px;
				margin-top: 2px;
			}
			
			header>.mui-row>.user-avatar {
				height: 44px;
				text-align: center;
			}
			
			header>.mui-row>.user-avatar>img {
				display: block;
				width: 34px;
				height: 34px;
				margin: 0 auto;
				margin-top: 5px;
				margin-left: 3px;
				border-radius: 50%;
				position: relative;
				right: 5px;
			}
			
			#search {
				width: 100%;
				height: 100%;
				/*background-color: red;*/
				position: relative;
				z-index: 999;
				top: -42px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<div class="mui-row">
				<div class="mui-col-sm-11 mui-col-xs-11">
					<div class="mui-input-row mui-search">
						<input disabled="disabled" type="search" class="mui-input-clear" placeholder="搜索感兴趣的内容">
						<div id="search"></div>
					</div>
				</div>
				<div class="user-avatar mui-col-sm-1 mui-col-xs-1">
					<img id="user-img" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=8232468,2916696848&fm=27&gp=0.jpg" alt="" />
				</div>
			</div>
		</header>

		<div class="mui-content">

		</div>
	</body>
	<script src="./js/mui.min.js"></script>
	<script src="./js/ip.js" type="text/javascript"></script>
	<script type="text/javascript">
		//启用双击监听	
		mui.init({
			beforeback:function(){
			//实现自己的逻辑
				plus.runtime.quit();
				return false;//return false时不再执行后退逻辑
			},
			gestureConfig: {
				doubletap: true
			},
			subpages: [{
				url: 'index-child.html',
				id: 'index-child',
				styles: {
					top: '44px',
					bottom: '0px'
				}
			}]
		});
		ajax() 
		function ajax(){
			mui.ajax('http://' + ip + '/xiaojv/Api/index.php?p=front&m=islogin&a=islogin', {
					data: {},
					dataType: 'json', //服务器返回json格式数据
					type: 'get', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；           
					success: function(data) {
						if(data.msg == 200) {
							selectUser();
						} else {
							mui.openWindow({
								url: 'login.html'
							});
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
						console.log(type);
					}
				});
		}
		document.querySelector('#search').addEventListener('tap', function() {
			mui.openWindow({
				url: 'search.html',
				id: 'search',
			})
		})

		document.querySelector('#user-img').addEventListener('tap', function() {
			mui.openWindow({
				url: 'template/me.html',
				id: 'me',
			})
		})

		function selectUser() {
			mui.ajax('http://' + ip + '/xiaojv/Api/index.php?p=front&m=me&a=me', {
				dataType: 'json', //服务器返回json格式数据
				type: 'get', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				success: function(data) {
					document.querySelector('#user-img').src = data.data[0].avatar;
				},
				error: function(xhr, type, errorThrown) {
					console.log(type);
				}
			});
		}
	</script>

</html>